package handler

import (
	"github.com/sirupsen/logrus"
	"gofile/src/util"
	"io/ioutil"
	"net/http"
)

func RawHandler(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	file := params.Get("file")
	b, err := ioutil.ReadFile(file) // just pass the file name
	if err != nil {
		util.ProcessResult("读取文件"+file+"失败", err, w)
		return
	}
	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	bSzie, err := w.Write(b)
	if err != nil {
		util.ProcessResult("返回文件"+file+"失败", err, w)
		return
	}
	logrus.Infoln(bSzie)
}
